1.9 Permission and Attribute Management
chmod — Change File Mode Bits Utility
Format:
chmod [options] mode file...
Common Options:
-
-R: Recursively modify file permissions for directories and their sub-contents.
-
-v: Verbose mode (display a diagnostic for every file processed).
-
--reference=file: Set permissions to match those of the specified reference file.
-
--changes: Like verbose, but report only when a change is actually made.
-
--silent / --quiet: Suppress most error and informational messages.
File permissions are divided among the file owner, group members, and other users, represented by u, g, and o respectively. The standard permissions are read, write, and execute, represented by r, w, and x. Permissions can also be represented numerically via octal values as follows:
| Permission | Octal Value |
|---|---|
| r | 4 |
| w | 2 |
| x | 1 |
Examples:
$ chmod u+x \~/bin/repo
$ chmod go-w \~/bin/repo
$ chmod 751 file
(Note: In the third example, octal 7 grants read, write, and execute permissions to the owner; 5 grants read and execute permissions to group members; and 1 grants execute-only access to other users).
chown — Change File Ownership Utility
Format:
chown [options] owner[:group] file_or_directory
Common Options:
-
-R: Recursively modify ownership across directories and all sub-contents.
-
-v: Verbose mode (display detailed output for every file processed).
-
-c: Report only when an actual ownership change takes place.
-
-f: Force mode (suppress most error messages regarding ownership modification failures).
-
--reference=file: Set ownership and group properties to match those of the specified reference file.
-
-h: Modify the owner/group of a symbolic link itself instead of the target file it references.
Examples:
$ chown david file.txt
$ chown -R david:users /project
chgrp — Change Group Ownership Utility
Format:
chgrp [options] group_name file...
Or:
chgrp [options] group_name directory
Common Options:
-
-R: Recursively modify group ownership for directories and all sub-contents.
-
-v: Verbose mode (display detailed processing diagnostics).
-
-c: Report only when a group ownership change takes place.
-
-f: Force mode (suppress most error messages regarding group modification failures).
-
-h: Modify the group of a symbolic link itself instead of the destination file it references.
-
--reference=file: Set group ownership to match that of the specified reference file.
Examples:
$ chgrp users file1 file2 file3
$ chgrp -R developers /project
$ chgrp --reference=template.txt newfile.txt